import os
import glob
import shutil
path = '/data/ICE/ICECollection/BaseData/src_data/batch2'
extract_path = '/data/ICE/DataSetCollection/batch2_batch3_tiny'
extract_images_path = os.path.join(extract_path, 'JPEGImages')
extract_xml_path = os.path.join(extract_path, 'xml')

folders = os.listdir(path)
all_rgb_images = []
for folder in folders:
    folder_path = os.path.join(path, folder)
    if not os.path.isdir(folder_path):
        continue
    print(folder_path)
    rgb_path = os.path.join(folder_path, 'rgb/cam0')
    rgb_images_path = glob.glob(rgb_path + "/*")
    if len(rgb_images_path) > 1:
        all_rgb_images.extend(rgb_images_path)

print(len(all_rgb_images))

last_rgb_images_path = []
# extract_images_dep = glob.glob(extract_images_path + '/*')
extract_images_dep = os.listdir(extract_images_path)
for rgb_path_name in all_rgb_images:
    rgb_name = os.path.basename(rgb_path_name)
    if rgb_name in extract_images_dep:
        last_rgb_images_path.append(rgb_path_name)
    elif 'cam0' + rgb_name in extract_images_dep:
        last_rgb_images_path.append(rgb_path_name)
    elif 'cam1' + rgb_name in extract_images_dep:
        last_rgb_images_path.append(rgb_path_name)
    elif 'cam0_' + rgb_name in extract_images_dep:
        last_rgb_images_path.append(rgb_path_name)
    elif 'cam1_' + rgb_name in extract_images_dep:
        last_rgb_images_path.append(rgb_path_name)

print(len(last_rgb_images_path))
print(len(extract_images_dep))

saveDir = '/data/ICE/RGBCollection'
# for rgb_image_src_path in last_rgb_images_path:
#     shutil.copy(rgb_image_src_path, saveDir)
